import doctest


def error(action = "index" , flash='no search found') :
    redirect(url(action))
    session.flash =  flash
    return T("done")
    
def index():     
  
###take vars from post

    searchPlace = str(request.post_vars.searchPlace)
   #list for placeIDs
    searchPlace = '%' + searchPlace + '%'
    l = []
    t = []  
    #search in database in places , tags and category for the word in the searchBox
    if searchPlace != None :
    #search by place name
        placeId = db(db.places.name.like(searchPlace)).select()
        
        for row in placeId:
            l.append(row)
        
        #search by tag name
        tag_id  = db(db.tags.name.lower().like(searchPlace)).select()
        for row in tag_id:
            t.append(row)
            
      # you can't use row.id directly I don't know why !
        place =  db(db.places_tags.tag.belongs(t)).select()
    
        for row in place :
            l.append(row)
            
        #search by category
        cat  =  db(db.categories.name.lower().like( searchPlace) ).select()
        t = []
        for row in cat:
            t.append(row)
            
        place =  db(db.places.category.belongs(t)).select()
        for row in place :
            l.append(row)

        #return rows of data
    placeData  = db(db.places.id.belongs(l)).select()
        
    return  dict(placeData = placeData)
